package leetcode.part1;

import org.junit.Test;

// important！
public class S7 {
    public int maxProfit(int[] prices) {
        int min=Integer.MAX_VALUE;
        int profit=0;
        for (int i = 0; i < prices.length; i++) {
            // 找到最低买入点
            if (prices[i]<min){
                min=prices[i];
            }
            int nowProfit=prices[i]-min;
            if (nowProfit>profit) profit=nowProfit;

        }
        return profit;
    }
    @Test
    public void test(){
        int[] nums= {7,6,4,3,1};
        System.out.println(maxProfit(nums));
    }
}
